package cn.zz.veggie.core.enums.biz;

import lombok.AllArgsConstructor;

/**
 * @author zhongq
 * @since 2024/6/1
 */

@AllArgsConstructor
public enum OrderStatus {
	deleted(0, "已删除"),
	active(1, "启用");

	public final int status;
	private final String desc;

	public static boolean canChangeTo(Integer curr, Integer to) {
		return curr != null && to != null && curr < to;
	}

	public static boolean isMatch(Integer code, OrderStatus status) {
		return status != null && status.status == code;
	}

	// 通过 code 获取枚举实例
	public static OrderStatus fromCode(int code) {
		for (OrderStatus status : OrderStatus.values()) {
			if (status.status == code) {
				return status;
			}
		}
		throw new IllegalArgumentException("Unknown code: " + code);
	}
}